home *** CD-ROM | disk | FTP | other *** search
- Path: sunsite.doc.ic.ac.uk!ukc!news
- From: bec1@ukc.ac.uk (Ben Clifton)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Removing and Adding Gadgets
- Date: 29 Jan 1996 16:56:07 GMT
- Organization: Computing Lab, University of Kent at Canterbury, UK.
- Message-ID: <3568.6602T1016T654@ukc.ac.uk>
- NNTP-Posting-Host: merlin.ukc.ac.uk
- X-Newsreader: THOR 2.22 (Amiga;TCP/IP) *UNREGISTERED*
-
-
- I`m in need of help.
-
- I currently have a set of gadgets on a window that I would like to change
- the gadget text on. There is no function I can find in the RKMs to change
- this for me and changing the GadetText field of the gadgets result in non
- centred gadget texts and memory over write. The follow function does not work
- correctly - first time it is called it works fine. Second time it crashes all
- systems. No enforcer hits are generated. No mungwall reports generated.
-
- Can anyone suggest what I`m doing wrong or missing, or explain a better way of
- doing this.
-
- Thanks in advance.
-
- Ben
-
- ------
-
- void ChangeUserGadgets( int ListNo )
- {
- struct FM_UserGadget *ptr;
- UWORD offx, offy;
- UWORD loop;
- struct NewGadget newgad;
- struct Gadget *Gad = NULL;
- struct Gadget *Gad2;
- APTR Cla;
- int StartGad, n1;
-
- offx = Scr->WBorLeft;
- offy = Scr->WBorTop + Scr->Font->ta_YSize+1;
-
- RemoveGList( MainWindow, MainWindowGList, ~0 );
-
- FreeGadgets( MainWindowGList );
-
- if( ListNo == 0 )
- StartGad = MainWindow_UserGad1;
- else
- StartGad = MainWindow_UserGad18;
-
-
- if( SideInfo.NUserGads[0] < USERGAD_MAX/2 )
- n1 = SideInfo.NUserGads[0];
- else
- n1 = USERGAD_MAX/2;
-
- for( loop=SideInfo.NUserGadsStart[ListNo]-1; loop<n1; loop++ )
- {
- ptr = GetUserGadsNode( ListNo, loop );
- FreeVec( MainWindowNewGadgets[StartGad+loop].ng_GadgetText );
- if( MainWindowNewGadgets[StartGad+loop].ng_GadgetText = AllocVec( 10 ,
- MEMF_PUBLIC|MEMF_CLEAR ))
- strcpy( MainWindowNewGadgets[StartGad+loop].ng_GadgetText, ptr->
- gadgetname ); else
- return;
- }
-
- MainWindowVisualInfo = GetVisualInfoA( Scr, NULL);
- MainWindowDrawInfo = GetScreenDrawInfo( Scr);
-
- MainWindowGList = NULL;
- Gad = CreateContext( &MainWindowGList );
- if( Gad )
- {
- DoRTRequest( "Create New Gadgets", "Okay", "Debug Req" );
- for ( loop=0 ; loop<67 ; loop++ )
- {
- if (MainWindowGadgetTypes[loop] != 198)
- {
- CopyMem((char * )&MainWindowNewGadgets[loop], ( char * )&newgad,
- (long)sizeof( struct NewGadget ));
- newgad.ng_VisualInfo = MainWindowVisualInfo;
- newgad.ng_LeftEdge += offx;
- newgad.ng_TopEdge += offy;
- MainWindowGadgets[ loop ] = NULL;
- MainWindowGadgets[ newgad.ng_GadgetID - MainWindowFirstID ] = Gad =
- CreateGadgetA( MainWindowGadgetTypes[loop], Gad, &newgad, newgad.ng_UserData
- );
- }
- }
- for ( loop=0 ; loop<67 ; loop++ )
- {
- if (MainWindowGadgetTypes[loop] == 198)
- {
- MainWindowGadgets[ loop ] = NULL;
- Cla = NULL;
- if (Gad)
- MainWindowGadgets[ loop ] = Gad2 = (struct Gadget *) NewObjectA(
- (struct IClass *)Cla, MainWindowNewGadgets[ loop ].ng_GadgetText,
- MainWindowNewGadgets[ loop ].ng_UserData );
- }
- }
-
- AddGList( MainWindow, MainWindowGadgets[0], 0, ~0, NULL );
-
- RefreshGList( MainWindowGList, MainWindow, NULL, ~0);
- GT_RefreshWindow( MainWindow, NULL);
-
- SetSliderGadgets();
- }
- else
- {
- DoRTRequest( "Error Recreating Gadgets (Context)", "Okay", "Error from
- FileMan" );
- }
-
- }
-
-
- +--------------------------------------------------------------+
- | The Ephebians made wine out of anything they could put in a |
- | bucket, and ate anything that couldn't climb out of one. |
- | -- (Terry Pratchett, Pyramids) |
- +-------------+----------------+-------------------------------+
- | Ben Clifton | bec1@ukc.ac.uk | Talk to me in #AmigaCafe |
- +-------------+----------------+-------------------------------+
-
- Join the TAGLINE CHAIN !!, adopt and add 1. This one is copy #5
-
-